<template>
  <div class="city-wrapper">
    <CityHeader></CityHeader>
    <CitySearch :cities='cities'></CitySearch>
    <CityList :cities='cities' :hotCities='hotCities' :cityIndex='cityIndex'></CityList>
    <CityAlphabet :cities='cities' @send="getCityIndex"></CityAlphabet>
  </div>
</template>

<script>
import CityHeader from "./components/Header";
import CitySearch from "./components/Search";
import CityList from "./components/List";
import CityAlphabet from "./components/Alphabet";
import axios from "axios";
export default {
  name: "city",
  data() {
    return {
        cities:[],
        hotCities:[],
        cityIndex:''
    };
  },
  methods: {
    getCityInfo() {
      axios.get("/api/city.json").then(this.getCityinfoSucc);
    },
    getCityinfoSucc(res) {    
      const resData = res.data;
      if (resData.ret && resData.data) {
        this.cities = resData.data.cities
        this.hotCities = resData.data.hotCities
        // console.log(resData.data.cities,resData.data.hotCities);
      }
    },
    getCityIndex(cityIndex){
      this.cityIndex = cityIndex
    }
  },
  mounted() {
    this.getCityInfo();
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  }
};
</script>

<style lang="stylus" scoped>
.city-wrapper {
  touch-action: none;
}
</style>
